﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace NJL.WebUsers
{
    public partial class SearchAttractions :BasePageVisitor
    {
        NJL.BLL.NJL_ATTRACTION bllAttr = new BLL.NJL_ATTRACTION();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                txtkeywords.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById(" + bntSearch.ClientID + ").click();return false;}} else {return true}; ");
                txtkeywords.Text = Request.QueryString["keywords"];
                bind();
            }
        }
        void bind()
        {
            Page.Title = "景点名胜";
            DataSet ds;
            if (WEBSITE_FOCUS_CITY_CODE != "")
            {
                ds = bllAttr.GetAllList("ATTRACTION_NAME like '%" + Request.QueryString["keywords"] + "%' or ATTRACTION_TAG like '%" + Request.QueryString["keywords"] + "%' and NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' and AREA_CODE='" + WEBSITE_FOCUS_CITY_CODE + "'");
            }
            else
            {
                ds = bllAttr.GetAllList("ATTRACTION_NAME like '%" + Request.QueryString["keywords"] + "%' or ATTRACTION_TAG like '%" + Request.QueryString["keywords"] + "%' and NJL_SYS_BASE_ID='" + WEBSITE_CODE + "'");
            }
            if (ds.Tables[0].Rows.Count > 10)
            {
               string[] param = { "keywords","cc" };
               pager.InnerHtml=Royalsoft.Common.Pager.GetPageNum(ds, rptAttr, 10, param);
            }
            else
            {
                rptAttr.DataSource = ds;
                rptAttr.DataBind();
            }
            litCount.Text = ds.Tables[0].Rows.Count.ToString();
            #region 标签搜索+1
            NJL.BLL.NJL_CS_TAG bllTag = new BLL.NJL_CS_TAG();
            NJL.Model.NJL_CS_TAG modelTag;
            ds = bllTag.GetList("TAG='" + Request.QueryString["keywords"] + "' and TAG_TYPE='1'");
            if (ds.Tables[0].Rows.Count > 0)
            {
                modelTag = bllTag.GetModel(ds.Tables[0].Rows[0][0].ToString());
                modelTag.SEARCH_COUNT += 1;
                if (bllTag.Update(modelTag))
                {
                }
            }
            #endregion
      
        }

        protected void bntSearch_Click(object sender, EventArgs e)
        {
            Response.Redirect("SearchAttractions.aspx?keywords=" + Server.UrlEncode(txtkeywords.Text.Trim()));
        }
    }
}